package xcmg.device.service.account;

import com.github.pagehelper.PageInfo;
import yb.ecp.fast.infra.util.PageHelperPlus;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xcmg.device.dao.entity.account.ArapDetailDO;
import xcmg.device.dao.mapper.account.ArrearsStatisticsMapper;
import xcmg.device.service.vo.account.ArapDetailVO;
import xcmg.device.service.vo.account.ArrearsStatisticsParam;
import xcmg.device.service.vo.account.ArrearsStatisticsVO;
import yb.ecp.fast.infra.infra.PageCommonVO;
import yb.ecp.fast.infra.infra.SearchCommonVO;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/8/27.
 */
@Service
public class ArrearsStatisticsService {
    @Autowired
    private ArrearsStatisticsMapper arrearsStatisticsMapper;

    public PageCommonVO servicePersonList(SearchCommonVO<ArrearsStatisticsParam> condition) {
        PageCommonVO result = new PageCommonVO();
        PageHelperPlus.orderBy("SERVICE_PERSON_NAME desc");
        PageHelperPlus.startPage(condition.getPageNum(), condition.getPageSize());
        List<ArrearsStatisticsVO> doList = arrearsStatisticsMapper.servicePersonList(condition.getFilters());
        List<ArrearsStatisticsVO> voList = new ArrayList<>();
        for (ArrearsStatisticsVO entity : doList) {
            ArrearsStatisticsVO model = new ArrearsStatisticsVO();
            BeanUtils.copyProperties(entity, model);
            voList.add(model);
        }
        result.setPageInfo(new PageInfo(doList));
        result.setPageInfoList(voList);
        return result;
    }

    public PageCommonVO clientList(SearchCommonVO<ArrearsStatisticsParam> condition) {
        PageCommonVO result = new PageCommonVO();
        PageHelperPlus.orderBy("ACC_ORG_id desc");
        PageHelperPlus.startPage(condition.getPageNum(), condition.getPageSize());
        List<ArrearsStatisticsVO> doList = arrearsStatisticsMapper.clientList(condition.getFilters());
        List<ArrearsStatisticsVO> voList = new ArrayList<>();
        for (ArrearsStatisticsVO entity : doList) {
            ArrearsStatisticsVO model = new ArrearsStatisticsVO();
            BeanUtils.copyProperties(entity, model);
            voList.add(model);
        }
        result.setPageInfo(new PageInfo(doList));
        result.setPageInfoList(voList);
        return result;
    }

    public PageCommonVO orderDetailList(SearchCommonVO<ArrearsStatisticsParam> condition) {
        PageCommonVO result = new PageCommonVO();
        PageHelperPlus.orderBy("BILL_DATE desc");
        PageHelperPlus.startPage(condition.getPageNum(), condition.getPageSize());
        List<ArapDetailDO> doList = arrearsStatisticsMapper.orderDetailList(condition.getFilters());
        List<ArapDetailVO> voList = new ArrayList<>();
        for (ArapDetailDO entity : doList) {
            ArapDetailVO model = new ArapDetailVO();
            BeanUtils.copyProperties(entity, model);
            voList.add(model);
        }
        result.setPageInfo(new PageInfo(doList));
        result.setPageInfoList(voList);
        return result;
    }
}
